import 'package:json_annotation/json_annotation.dart';

part 'read_entity.g.dart';

@JsonSerializable()
class ReadEntity {
  /// 消息接收者ID
  @JsonKey(name: "receiver_id", defaultValue: '')
  String receiverId;

  /// 消息接收者昵称
  @JsonKey(name: "receiver_nick", defaultValue: '')
  String receiverNick;

  /// 消息接收者头像
  @JsonKey(name: "receiver_avatar", defaultValue: '')
  String receiverAvatar;

  /// 默认构造函数
  ReadEntity({
    this.receiverId = '',
    this.receiverNick = '',
    this.receiverAvatar = '',
  });

  String getNick() {
    return receiverNick.isNotEmpty ? receiverNick : ' ';
  }

  /// 从JSON映射创建消息实体对象
  factory ReadEntity.fromJson(Map<String, dynamic> json) => _$ReadEntityFromJson(json);

  /// 将消息实体对象转换为JSON映射
  Map<String, dynamic> toJson() => _$ReadEntityToJson(this);

  factory ReadEntity.fromSocketJson(Map<String, dynamic> json) {
    return ReadEntity(
      receiverId: json['sender_id'] ?? '',
      receiverNick: json['sender_nick'] ?? '',
      receiverAvatar: json['sender_avatar'] ?? '',
    );
  }
}

class SessionReadEntity extends ReadEntity {
  /// 会话已读消息
  @JsonKey(name: "msg_ids", defaultValue: [])
  List<String> msgIds;

  /// 会话ID
  @JsonKey(name: "conv_id", defaultValue: '')
  String convId;

  /// 会话类型
  @JsonKey(name: "conv_type", defaultValue: 0)
  int convType;

  /// 默认构造函数
  SessionReadEntity({
    this.msgIds = const [],
    this.convId = '',
    this.convType = 0,
  }) : super();
}
